import JSEncrypt from 'jsencrypt';
// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3ZkUx85eY24OguxChupDRUB2KLaE6TK3Rnuqkp1qh1eaqn1FV7utW0n6IPKKPub5XzwRSwnYQDFvNdqTJNYwk8KF+7nSOl9x5vEsZ/oWakslQJY9rUI3wtmsi/WRQDuruts5lAyT7CDjNaTrT0Y7n1g6Q7v6fT9gmBEU0LDcgNwIDAQAB';

// 前端不建议存放私钥 不建议解密数据 因为都是透明的意义不大
const privateKey = 'MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBANCSEzIrPD+EDHv8ALdZVQef9RkSsYjmcMtfhSBCmXekFKpcp/63BHdW19u3sPuy7kihd70PB3RImYOdwayqO1/lyhfO5lI6yOXa3flOEzWEME86Vp668CmRaFruL+eOiiWiKHCgCN7zWb0dRdZP3lCBzIo4IiAMi3GOymy+NnXZAgMBAAECgYABD2q/RxxqJj2w3Mw4tKnU2KmZJnV2SdWXzn42LXvrXzPd+dTjEpVhg6Ja/CShmcWI40SqRDi4VghtK2wgCtsziz4JHcaeyX9Nw2ACr08HLT5o4dacafAz+cddNY7lkhr7wE7/0J8GhzjJCqsDcnHGSuJ1wJwR5x7sxRtvu2pYAQJBAPHP/30Qi5Gb9nZLyLh/g/kVvOcRtDUTE9Aj7HIbdc4zYmmuK3nmYRSbmUcgglOQ9yF7Nb0cmgeSTyIF+O84KkECQQDczsls0rVx/2WmZEHLJjO/5R+HCMi6hYyMNBWD5wHjCrABO2H7jdk77As6OFdBnuViX8UrBVlpxWdXF61V9fWZAkBv1cjNqKdEEqOsFmSgn6kDvD//hjqYCViyfMrQA086rJ0pTzogSKJBi60aLjjYOUVyoK875Ux/j/U1QRneWVWBAkAKcc2dVCo5BjesszlZfqkb/p6LKKM2D3MifqQ15Qt1zd+db02nNIJ+DyBI1Llr5TQ8fwM4kbw1AJ1uxTPxyPyhAkEAsbQgY2HkmEuwHHQyuMkfznEGAU8uimImyu2vAnsHgsfAWp7iZ++19rL1yAu2tI0Rv3wkogxByRUtO9MvOJau2w==';

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}

